<?php
namespace App\Http\Controllers\AppApi\Msg;

use App\Models\Main\UserScoreModel;
use Illuminate\Http\Request;

class ScoreController extends BaseController
{
    /**
     * 准信息
     * 制作者：九哥
     */

    protected $model;

    public function __construct()
    {
        parent::__construct();
        $this->model = new UserScoreModel();
    }

    /**
     * 消息窗口获取
     */
    public function getIndex(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $cate = $request->cate;
        if (!$token) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $dataArr = array(
            'com' => array(
                'num' => 0,
                'score' => 0,
            ),
            'fac' => array(
                'num' => 0,
                'score' => 0,
            ),
            'staff' => array(
                'num' => 0,
                'score' => 0,
            ),
            'total' => array(
                'num' => 0,
                'score' => 0,
            ),
        );
        $query = $this->model->where('uid',$uid);
        $com = $query->where('genre',1)->count();
        $fac = $query->where('genre',2)->count();
        $staff = $query->where('genre',3)->count();
        $totalNum = $com + $fac + $staff;
        $totalScore = $com * 5 + $fac * 3 + $staff * 1;
        $dataArr = array(
            'com' => array(
                'num' => $com,
                'score' => $com * 5,
            ),
            'fac' => array(
                'num' => $fac,
                'score' => $fac * 3,
            ),
            'staff' => array(
                'num' => $staff,
                'score' => $staff * 1,
            ),
            'total' => array(
                'num' => $totalNum,
                'score' => $totalScore,
            ),
        );
        return $this->toJson(0,$dataArr);
    }
}
